#ifndef DATAPARSE_H
#define DATAPARSE_H

#include "dataformat.h"

#include <QObject>
#include <QJsonObject>
#include <QNetworkReply>
#include <QNetworkAccessManager>

class DataParse : public QObject
{
    Q_OBJECT
public:
    explicit DataParse(QObject *parent = nullptr);
    void getWeatherInfo(const QString& city);

    // 请求类型枚举
    enum RequestType { Future, Current };

private slots:
    void futureReply(QNetworkReply *reply);
    void currentReply(QNetworkReply *reply);

private:
    QNetworkAccessManager* m_Current;
    QNetworkAccessManager* m_Future;

    const QString m_apiKey = "";

    // 创建公共通用API网址
    QUrl buildCommonUrl(const QString& city, RequestType type) const;
    void getWeatherData(const QString& city, RequestType type);

    void parseFutureData(const QByteArray& data);
    void parseCurrentData(const QByteArray& data);

signals:
    void errorOccurred(const QString &error);
    void FutureInfoReady(const QVector<FutureDays> &futuredays);
    void CurrentInfoReady(const CurrentDay &currentday);
};

#endif // DATAPARSE_H
